import pymysql


def excute(sql):
    conn = pymysql.connect(host="user-p2p-test.itheima.net",
                           port=3306,
                           user='root',
                           password='Itcast_p2p_20191228',
                           database='czbk_member',
                           charset='utf8')

    cursor = conn.cursor()
    cursor.execute(sql)
    try:
        if sql.split()[0].lower() == 'select':
            return cursor.fetchall()
        else:
            conn.commit()
            return cursor.rowcount
    except Exception as e:
        print(e)
        conn.rollback()
    finally:
        if cursor:
            cursor.close()
        if conn:
            conn.close()








































